import os
import time

from selenium import webdriver
from selenium.webdriver.common.by import By


class Register:
    def __init__(self):

        self.url = "file:///" + os.path.abspath("../代码练习/html") + "/abc.html" #获取本地连接并访问
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get(self.url)
    def register1(self):
        self.driver.find_element(By.ID, 'user').send_keys('main123') #定位账号输入内容
        self.driver.find_element(By.ID, 'password').send_keys('123456') #定位密码输入内容
        self.driver.find_element(By.ID, 'tel').send_keys('13160407442') #定位手机号输入类容
        self.driver.find_element(By.ID, 'email').send_keys('1194971161@qq.com') #定位邮箱输入类容
        time.sleep(2)
        self.driver.find_element(By.XPATH, "//button[@type='submit' and @value='注册']").click()#定位注册并点击
    def register2(self):
        self.ur = self.driver.find_element(By.ID, 'idframe1') #定位到iframe
        self.driver.switch_to.frame(self.ur) #切换到指定的iframe
        self.driver.find_element(By.ID, 'userA').send_keys('main1231')
        self.driver.find_element(By.ID, 'passwordA').send_keys('1234561')
        self.driver.find_element(By.ID, 'telA').send_keys('13160407443')
        self.driver.find_element(By.ID, 'emailA').send_keys('1194971161@qq.com')
        time.sleep(2)
        self.driver.find_element(By.XPATH, "//button[@type='submitA' and @value='注册A']").click()
    def register3(self):
        self.driver.switch_to.default_content() #切换到指定的iframe主页
        self.ur1 = self.driver.find_element(By.NAME, 'myframe2')#定位想要指定的iframe
        self.driver.switch_to.frame(self.ur1) #切换到指定的iframe
        self.driver.find_element(By.ID, 'userB').send_keys('main1231')
        self.driver.find_element(By.ID, 'passwordB').send_keys('1234561')
        self.driver.find_element(By.ID, 'telB').send_keys('13160407443')
        self.driver.find_element(By.ID, 'emailB').send_keys('1194971161@qq.com')
        time.sleep(2)
        self.driver.find_element(By.XPATH, "//button[@type='submit' and @value='注册B']").click()

    def quit(self):
        time.sleep(2)
        self.driver.quit()


if __name__ == '__main__':
    register = Register()
    register.register1()
    register.register2()
    register.register3()
    register.quit()















